package com.booksystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.booksystem.entity.ProductReviewDO;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *   商品评价信息表数据访问接口
 * </p>
 * @author 段伟豪
 */
public interface ProductReviewMapper extends BaseMapper<ProductReviewDO> {

    /**
     * 根据商品ID查询评价列表并按时间倒序排列
     * @param productId 商品ID
     * @param offset 偏移量
     * @param limit 每页大小
     * @return 评价列表
     */
    @Select("SELECT * FROM product_review WHERE product_id = #{productId} AND is_approved = 1 ORDER BY create_time DESC LIMIT #{offset}, #{limit}")
    List<ProductReviewDO> selectReviewsByProductId(@Param("productId") Long productId, @Param("offset") int offset, @Param("limit") int limit);
}